// 临时文件 - 复制这个函数到 Terrain.cpp 替换 LoadTextures
bool Terrain::LoadTextures(LPDIRECT3DDEVICE9 device)
{
    // ========== 草地纹理：鲜艳的草绿色 ==========
    HRESULT hr = D3DXCreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8,
        D3DPOOL_MANAGED, &m_pTextureGrass);
    if (FAILED(hr))
        return false;

    if (SUCCEEDED(hr))
    {
        D3DLOCKED_RECT rect;
        m_pTextureGrass->LockRect(0, &rect, NULL, 0);
        DWORD* texels = static_cast<DWORD*>(rect.pBits);

        for (int y = 0; y < 64; ++y)
        {
            for (int x = 0; x < 64; ++x)
            {
                int i = y * 64 + x;

                // 鲜艳的草绿色（亮度超高，完全不可能看起来透明）
                int r = 100;
                int g = 220;
                int b = 80;

                // 8x8 草地方块网格
                bool isBorder = (x % 8 == 0 || y % 8 == 0);
                if (isBorder)
                {
                    // 深绿色边框
                    r = 70;
                    g = 180;
                    b = 60;
                }

                // 棋盘格交替
                if (((x / 8) + (y / 8)) % 2 == 0)
                {
                    r += 20;
                    g += 30;
                    b += 15;
                }

                // 确保颜色在有效范围内
                if (r < 0) r = 0; if (r > 255) r = 255;
                if (g < 0) g = 0; if (g > 255) g = 255;
                if (b < 0) b = 0; if (b > 255) b = 255;

                texels[i] = D3DCOLOR_ARGB(255, r, g, b);  // Alpha=255 完全不透明
            }
        }
        m_pTextureGrass->UnlockRect(0);
    }

    // ========== 泥土纹理：明亮的土黄色 ==========
    hr = D3DXCreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8,
        D3DPOOL_MANAGED, &m_pTextureDirt);
    if (FAILED(hr))
        return false;

    if (SUCCEEDED(hr))
    {
        D3DLOCKED_RECT rect;
        m_pTextureDirt->LockRect(0, &rect, NULL, 0);
        DWORD* texels = static_cast<DWORD*>(rect.pBits);
        for (int i = 0; i < 64 * 64; ++i)
        {
            // 明亮的土黄色（比原来亮得多）
            texels[i] = D3DCOLOR_ARGB(255,
                180 + rand() % 50,   // R: 180-230
                140 + rand() % 40,   // G: 140-180
                80 + rand() % 30);   // B: 80-110
        }
        m_pTextureDirt->UnlockRect(0);
    }

    // ========== 岩石纹理：明亮的灰色 ==========
    hr = D3DXCreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8,
        D3DPOOL_MANAGED, &m_pTextureRock);
    if (FAILED(hr))
        return false;

    if (SUCCEEDED(hr))
    {
        D3DLOCKED_RECT rect;
        m_pTextureRock->LockRect(0, &rect, NULL, 0);
        DWORD* texels = static_cast<DWORD*>(rect.pBits);
        for (int i = 0; i < 64 * 64; ++i)
        {
            // 明亮的灰色（比原来亮得多）
            int gray = 150 + rand() % 80;  // 150-230
            texels[i] = D3DCOLOR_ARGB(255, gray, gray, gray);
        }
        m_pTextureRock->UnlockRect(0);
    }

    // ========== 水面纹理：明亮的蓝色 ==========
    hr = D3DXCreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8,
        D3DPOOL_MANAGED, &m_pTextureWater);
    if (FAILED(hr))
        return false;

    if (SUCCEEDED(hr))
    {
        D3DLOCKED_RECT rect;
        m_pTextureWater->LockRect(0, &rect, NULL, 0);
        DWORD* texels = static_cast<DWORD*>(rect.pBits);
        for (int y = 0; y < 64; ++y)
        {
            for (int x = 0; x < 64; ++x)
            {
                // 明亮的蓝色水面
                int wave = (int)(sinf(x * 0.3f) * cosf(y * 0.3f) * 20.0f);
                int r = 60 + wave;
                int g = 150 + wave;
                int b = 230 + wave;
                if (r < 0) r = 0; if (r > 255) r = 255;
                if (g < 0) g = 0; if (g > 255) g = 255;
                if (b < 0) b = 0; if (b > 255) b = 255;
                texels[y * 64 + x] = D3DCOLOR_ARGB(255, r, g, b);
            }
        }
        m_pTextureWater->UnlockRect(0);
    }

    return true;
}
